home *** CD-ROM | disk | FTP | other *** search
/ C/C++ 3D Game Tools / C-C++ 3D Game Tools.iso / tools / algorith.txt < prev    next >
Text File  |  1997-02-25  |  50KB  |  1,386 lines

  1. From jdstone@destin.dazixco.ingr.com Fri Oct 14 22:13:59 1994
  2. From: jdstone@destin.dazixco.ingr.com (Jon Stone)
  3. Newsgroups: comp.graphics.algorithms,comp.answers,news.answers
  4. Subject: comp.graphics.algorithms Frequently Asked Questions (FAQ)
  5. Supersedes: <graphics_779018404@baggins.dazixco.ingr.com>
  6. Followup-To: comp.graphics.algorithms
  7. Date: 9 Oct 1994 10:00:06 GMT
  8. Organization: Intergraph Corp., Boulder CO
  9. Reply-To: jdstone@ingr.com
  10. NNTP-Posting-Host: destin.dazixco.ingr.com
  11. Summary: This posting contains a list of Frequently Asked
  12.      Questions (and their answers) about computer graphics
  13.      algorithms. It should be read by anyone who wishes to
  14.      post to the comp.graphics.algorithms newsgroup.
  15.  
  16. Archive-name:       graphics/algorithms-faq
  17. Version:           1.14
  18. Last-Modified:     September 29, 1994
  19. Posting-Frequency: monthly
  20.  
  21.  
  22.  
  23. Welcome to the FAQ for comp.graphics.algorithms!
  24.  
  25. Thanks to all who have contributed.  Corrections and contributions
  26. always welcome.
  27.  
  28. Changed items are marked with a |.
  29. New items are marked with a +.
  30. Items needing input are marked with a ?.
  31.  
  32. All ftp    references are of the form ftp://node/path
  33. All Mosaic references are of the form http://node/path
  34.  
  35. ----------------------------------------------------------------------
  36. Table of Contents
  37. ----------------------------------------------------------------------
  38.  
  39.    0) Charter of comp.graphics.algorithms
  40. |  1) Are the postings to comp.graphics.algorithms archived?
  41.    2) What are some must have books on graphics algorithms?
  42.    3) Are there any online references?
  43.    4) Where is all the source?
  44.    5) How do I rotate a 2D point?
  45.    6) How do I rotate a 3D point?
  46.    7) How do I find the distance from a point to a line?
  47.    8) How do I find intersections of 2 2D line segments?
  48.    9) How do I find the intersection of a line and a plane?
  49.   10) How do I rotate a bitmap?
  50.   11) How do I display a 24 bit image in 8 bits?
  51.   12) How do I fill the area an arbitrary shape?
  52.   13) How do I find the 'edges' in a bitmap?
  53. ? 14) How do I enlarge/sharpen/fuzz a bitmap?
  54.   15) How do I map a texture on to a shape?
  55.   16) How do I find the area/orientation of a polygon?
  56.   17) How do I find if a point lies within a polygon?
  57. ? 18) How do I find the intersection of two convex polygons?
  58.   19) How do I detect a 'corner' in a collection of points?
  59.   20) How do I generate a circle through three points?
  60.   21) How do I generate a bezier curve that is parallel to another bezier?
  61.   22) How do I split a bezier at a specific value for t?
  62.   23) How do I find a t value at a specific point on a bezier?
  63.   24) How do I fit a bezier curve to a circle?
  64.   25) What is ARCBALL?
  65.   26) Where can I find ARCBALL source?
  66.   27) How do I clip a polygon against a rectangle?
  67.   28) How do I clip a polygon against another polygon?
  68. ? 29) Where can I get source for Weiler/Atherton clipping?
  69. ? 30) How do I generate a spline to approximate (insert curve here)?
  70. ? 31) Where do I get source to display (raster font format)?
  71. ? 32) What is morphing/how is it done?
  72. ? 33) How do I draw an anti-aliased line/polygon/ellipse?
  73.   34) How do I determine the intersection between a ray and a polygon?
  74.   35) How do I determine the intersection between a ray and a sphere?
  75.   36) How do I determine the intersection between a ray and a bezier surface?
  76.   37) How do I ray trace caustics?
  77.   38) How do I quickly draw a filled triangle?
  78.   39) Where can I get source for Voronoi/Delaunay triangulation?
  79.   40) Where do I get source for convex hull?
  80.   41) What is the marching cubes algorithm?
  81. ? 42) What is the status of the patent on the "marching cubes" algorithm?
  82.   43) How do I do a hidden surface test (backface culling) with 3d points?
  83.   44) How do I do a hidden surface test (backface culling) with 2d points?
  84.   45) Where can I find graph layout algorithms?
  85. ? 46) Where can I find algorithms for 2D collision detection?
  86.   47) Where can I find algorithms for 3D collision detection?
  87.   48) 3D Noise functions and turbulence in Solid texturing.
  88.   49) How do I perform basic viewing in 3d?
  89. ? 50) How can you contribute to this FAQ?
  90.   51) Contributors.  Who made this all possible.
  91.  
  92. ----------------------------------------------------------------------
  93.  
  94. Subject: 0) Charter of comp.graphics.algorithms
  95.  
  96.     Comp.graphics.algorithms is an unmoderated newsgroup intended
  97.     as a forum for the discussion of the algorithms used in the
  98.     process of generating computer graphics.  These algorithms may
  99.     be recently proposed in published journals or papers, old or
  100.     previously known algorithms, or hacks used incidental to the
  101.     process of computer graphics.  The scope of these algorithms
  102.     may range from an efficient way to multiply matrices, all the
  103.     way to a global illumination method incorporating ray tracing,
  104.     radiosity, infinite spectrum modeling, and perhaps even
  105.     mirrored balls and lime jello.
  106.  
  107.     It is hoped that this group will serve as a forum for programmers
  108.     and researchers to exchange ideas and ask questions on recent
  109.     papers or current research related to computer graphics.
  110.  
  111.     comp.graphics.algorithms is not:
  112.  
  113.      - for requests for gifs, or other pictures
  114.      - for requests for image translator software (i.e. gif <--> jpg)
  115.  
  116. ----------------------------------------------------------------------
  117.  
  118. Subject: 1) Are the postings to comp.graphics.algorithms archived?
  119.  
  120. |   Yes.  The "official" archive is stored at:
  121. |
  122. |     http://www.cis.ohio-state/hypertext/faq/usenet/graphics/algorithms-faq/faq.html
  123. |     ftp://rtfm.mit.edu/pub/usenet-by-group/news.answers/graphics/algorithms-faq
  124. |
  125. |   Also available at:
  126. |
  127. |     ftp://wuarchive.wustl.edu/graphics/graphics/mail-lists/comp.graphics.algorithms
  128.  
  129.     It is archived in the same manner that all other newsgroups are
  130.     being archived there, namely there is an Index file with all the
  131.     subjects, and all the articles are being kept in a hierarchy based
  132.     on the year and month they are posted.
  133.  
  134. |   FYI, all usenet FAQ's are available with Mosaic via
  135. |
  136. |   http://www.cis.ohio-state/hypertext/faq/usenet/top.html
  137.  
  138.  
  139. ----------------------------------------------------------------------
  140.  
  141. Subject: 2) What are some must have books on graphics algorithms?
  142.  
  143.     The keywords in brackets are used to refer to the books in later
  144.     questions.  They generally refer to the first author except where
  145.     it is necessary to resolve ambiguity or in the case of the Gems.
  146.  
  147.  
  148.     Basic computer graphics, rendering algorithms,
  149.     ----------------------------------------------
  150.  
  151.     [Foley]
  152.     Computer Graphics: Principles and Practice (2nd Ed.),
  153.     J.D. Foley, A. van Dam, S.K. Feiner, J.F. Hughes, Addison-Wesley
  154.     1990, ISBN 0-201-12110-7
  155.  
  156.     [Rogers:Procedural]
  157.     Procedural Elements for Computer Graphics,
  158.     David F. Rogers, McGraw Hill 1985, ISBN 0-07-053534-5
  159.  
  160.     [Rogers:Mathematical]
  161.     Mathematical Elements for Computer Graphics 2nd Ed.,
  162.     David F. Rogers and J. Alan Adams, McGraw Hill 1990, ISBN
  163.     0-07-053530-2
  164.  
  165.     [Watt:3D]
  166.     _3D Computer Graphics, 2nd Edition_,
  167.     Alan Watt, Addison-Wesley 1993, ISBN 0-201-63186-5
  168.  
  169.     [Glassner:RayTracing]
  170.     An Introduction to Ray Tracing,
  171.     Andrew Glassner (ed.), Academic Press 1989, ISBN 0-12-286160-4
  172.  
  173.     [Gems I]
  174.     Graphics Gems,
  175.     Andrew Glassner (ed.), Academic Press 1990, ISBN 0-12-286165-5
  176.  
  177.     [Gems II]
  178.     Graphics Gems II,
  179.     James Arvo (ed.), Academic Press 1991, ISBN 0-12-64480-0
  180.  
  181.     [Gems III]
  182.     Graphics Gems III,
  183.     David Kirk (ed.), Academic Press 1992, ISBN 0-12-409670-0 (with
  184.     IBM disk) or 0-12-409671-9 (with Mac disk)
  185.  
  186.     [Gems IV]
  187.     Graphics Gems IV,
  188.     Paul S. Heckbert (ed.), Academic Press 1994, ISBN 0-12-336155-9
  189.     (with IBM disk) or 0-12-336156-7 (with Mac disk)
  190.  
  191.     [Watt:Animation]
  192.     Advanced Animation and Rendering Techniques,
  193.     Alan Watt, Mark Watt, Addison-Wesley 1992, ISBN 0-201-54412-1
  194.  
  195.     [Bartels]
  196.     An Introduction to Splines for Use in Computer Graphics and
  197.         Geometric Modeling,
  198.     Richard H. Bartels, John C. Beatty, Brian A. Barsky, 1987, ISBN
  199.     0-934613-27-3
  200.  
  201.     [Farin]
  202.     Curves and Surfaces for Computer Aided Geometric Design:
  203.     A Practical Guide, 3rd Edition, Gerald E. Farin, Academic Press
  204.     1993. ISBN 0-12-249052-5
  205.  
  206.     [Prusinkiewicz]
  207.     The Algorithmic Beauty of Plants,
  208.     Przemyslaw W. Prusinkiewicz, Aristid Lindenmayer, Springer-Verlag,
  209.     1990, ISBN 0-387-97297-8, ISBN 3-540-97297-8
  210.  
  211.     [Oliver]
  212.     Tricks of the Graphics Gurus,
  213.     Dick Oliver, et al. (2) 3.5 PC disks included, $39.95 SAMS Publishing
  214.  
  215.     [Hearn]
  216.     Introduction to computer graphics,
  217.     Hearn & Baker
  218.  
  219.  
  220.     For image processing,
  221.     ---------------------
  222.  
  223.     [Barnsley]
  224.     Fractal Image Compression,
  225.     Michael F. Barnsley and Lyman P. Hurd, AK Peters, Ltd, 1993 ISBN
  226.     1-56881-000-8
  227.  
  228.     [Jain]
  229.     Fundamentals of Image Processing,
  230.     Anil K. Jain, Prentice-Hall 1989, ISBN 0-13-336165-9
  231.  
  232.     [Castleman]
  233.     Digital Image Processing,
  234.     Kenneth R. Castleman, Prentice-Hall 1979, ISBN 0-13-212365-7
  235.  
  236.     [Pratt]
  237.     Digital Image Processing, Second Edition,
  238.     William K. Pratt, Wiley-Interscience 1991, ISBN 0-471-85766-1
  239.  
  240.     [Gonzalez]
  241.     Digital Image Processing (2nd Ed.),
  242.     Rafael C. Gonzalez, Paul Wintz, Addison-Wesley 1987, ISBN
  243.     0-201-11026-1
  244.  
  245.     [Russ]
  246.     The Image Processing Handbook,
  247.     John C. Russ, CRC Press 1992, ISBN 0-8493-4233-3
  248.  
  249.     [Wolberg]
  250.     Digital Image Warping,
  251.     George Wolberg, IEEE Computer Society Press Monograph 1990, ISBN
  252.     0-8186-8944-7
  253.  
  254.  
  255.     Computational geometry,
  256.     ----------------------
  257.  
  258.     [Bowyer]
  259.     A Programmer's Geometry,
  260.     Adrian Bowyer, John Woodwark, Butterworths 1983, ISBN
  261.     0-408-01242-0 Pbk
  262.  
  263.     [O' Rourke]
  264.     Computational Geometry in C,
  265.     Joseph O'Rourke, Cambridge University Press 1994, ISBN
  266.     0-521-44592-2 Pbk, ISBN 0-521-44034-3 Hdbk
  267.  
  268.     [Mortenson]
  269.     Geometric Modeling,
  270.     Michael E. Mortenson, Wiley 1985, ISBN 0-471-88279-8
  271.  
  272.     [Preparata]
  273.     Computational Geometry: An Introduction,
  274.     Franco P. Preparata, Michael Ian Shamos, Springer-Verlag 1985,
  275.     ISBN 0-387-96131-3
  276.  
  277.  
  278. ----------------------------------------------------------------------
  279.  
  280. Subject: 3) Are there any online references?
  281.  
  282.     The computational geometry community maintains its own
  283.     bibliography of publications in or closely related to that
  284.     subject.  Every four months, additions and corrections are
  285.     solicited from users, after which the database is updated and
  286.     released anew.  As of September 1993, it contained 5356 bib-tex
  287.     entries.  It can be retrieved from
  288.  
  289.     ftp://cs.usask.ca/pub/geometry/geombib.tar.Z - bibliography proper
  290.  
  291.     ftp://cs.usask.ca/pub/geometry/geom.ps.Z     - PostScript format
  292.  
  293.     ftp://cs.usask.ca/pub/geometry/o-cgc19.ps.Z     - overview published
  294.         in '93 in SIGACT News and the Internat. J. Comput.  Geom. Appl.
  295.  
  296.     ftp://cs.usask.ca/pub/geometry/ftp-hints     - detailed retrieval info
  297.  
  298.     Announcing the ACM SIGGRAPH Online Bibliography Project, by
  299.     Stephen Spencer (biblio@siggraph.org)
  300.  
  301.     The database is available for anonymous FTP from the
  302.     ftp://siggraph.org/publications/bibliography directory.  Please
  303.     download and examine the file READ_ME in that directory for more
  304.     specific information concerning the database.
  305.  
  306.     'netlib' is a useful source for algorithms, member inquiries for
  307.     SIAM, and bibliographic searches.  For information, send mail to
  308.     netlib@ornl.gov, with "send index" in the body of the mail
  309.     message.
  310.  
  311.     You can also find free sources for numerical computation in C via
  312.     ftp://usc.edu/pub/C-numanal.  In particular, grab
  313.     numcomp-free-c.gz in that directory. 
  314.  
  315.     Check out Nick Fotis's computer graphics resources FAQ -- it's
  316.     packed with pointers to all sorts of great computer graphics
  317.     stuff.  This FAQ is posted biweekly to comp.graphics.
  318.  
  319.  
  320. ----------------------------------------------------------------------
  321.  
  322. Subject: 4) Where is all the source?
  323.  
  324.     Graphics Gems source code.
  325.     ftp://princeton.edu:pub/Graphics/GraphicsGems
  326.  
  327.     General 'stuff'
  328.     ftp://wuarchive.wustl.edu/graphics/graphics
  329.  
  330.  
  331. ----------------------------------------------------------------------
  332.  
  333. Subject: 5) How do I rotate a 2D point?
  334.  
  335.     In 2-D, the 2x2 matrix is very simple.  If you want to rotate a
  336.     column vector v by t degrees using matrix M, use
  337.  
  338.         M = {{cos t, -sin t}, {sin t, cos t}} in M*v.
  339.  
  340.     If you have a row vector, use the transpose of M (turn rows into
  341.     columns and vice versa).  If you want to combine rotations, in 2-D
  342.     you can just add their angles, but in higher dimensions you must
  343.     multiply their matrices.
  344.  
  345.  
  346. ----------------------------------------------------------------------
  347.  
  348. Subject: 6) How do I rotate a 3D point?
  349.  
  350.     Assuming you want to rotate vectors around the origin of your
  351.     coordinate system. (If you want to rotate around some other point,
  352.     subtract its coordinates from the point you are rotating, do the
  353.     rotation, and then add back what you subtracted.) In 3-D, you need
  354.     not only an angle, but also an axis. (In higher dimensions it gets
  355.     much worse, very quickly.)  Actually, you need 3 independent
  356.     numbers, and these come in a variety of flavors.  The flavor I
  357.     recommend is unit quaternions: 4 numbers that square and add up to
  358.     +1.  You can write these as [(x,y,z),w], with 4 real numbers, or
  359.     [v,w], with v, a 3-D vector pointing along the axis. The concept
  360.     of an axis is unique to 3-D. It is a line through the origin
  361.     containing all the points which do not move during the rotation.
  362.     So we know if we are turning forwards or back, we use a vector
  363.     pointing out along the line. Suppose you want to use unit vector u
  364.     as your axis, and rotate by 2t degrees.  (Yes, that's twice t.)
  365.     Make a quaternion [u sin t, cos t]. You can use the quaternion --
  366.     call it q -- directly on a vector v with quaternion
  367.     multiplication, q v q^-1, or just convert the quaternion to a 3x3
  368.     matrix M. If the components of q are {(x,y,z),w], then you want
  369.     the matrix
  370.  
  371.         M = {{1-2(yy+zz),  2(xy-wz),  2(xz+wy)},
  372.              {  2(xy+wz),1-2(xx+zz),  2(yz-wx)},
  373.              {  2(xz-wy),  2(yz+wx),1-2(xx+yy)}}.
  374.  
  375.     Rotations, translations, and much more are explained in all basic
  376.     computer graphics texts.  Quaternions are covered briefly in
  377.     [Foley], and more extensively in several Graphics Gems, and the
  378.     SIGGRAPH 85 proceedings.
  379.  
  380.  
  381. ----------------------------------------------------------------------
  382.  
  383. Subject: 7) How do I find the distance from a point to a line?
  384.  
  385.  
  386.     Let the point be C (XC,YC) and the line be AB (XA,YA) to (XB,YB).
  387.     The length of the line segment AB is L:
  388.  
  389.         L=((XB-XA)**2+(YB-YA)**2)**0.5
  390.  
  391.     and
  392.             (YA-YC)(YA-YB)-(XA-XC)(XB-XA)
  393.         r = -----------------------------
  394.                         L**2
  395.  
  396.             (YA-YC)(XB-XA)-(XA-XC)(YB-YA)
  397.         s = -----------------------------
  398.                         L**2
  399.  
  400.     Let I be the point of perpendicular projection of C onto AB, the
  401.  
  402.         XI=XA+r(XB-XA)
  403.         YI=YA+r(YB-YA)
  404.  
  405.     Distance from A to I = r*L
  406.     Distance from C to I = s*L
  407.  
  408.     If r<0      I is on backward extension of AB
  409.     If r>1      I is on ahead extension of AB
  410.     If 0<=r<=1  I is on AB
  411.  
  412.     If s<0      C is left of AB (you can just check the numerator)
  413.     If s>0      C is right of AB
  414.     If s=0      C is on AB
  415.  
  416.  
  417. ----------------------------------------------------------------------
  418.  
  419. Subject: 8) How do I find intersections of 2 2D line segments?
  420.  
  421.     This problem can be extremely easy or extremely difficult depends
  422.     on your applications.  If all you want is the intersection point,
  423.     the following should work:
  424.  
  425.     Let A,B,C,D be 2-space position vectors.  Then the directed line
  426.     segments AB & CD are given by:
  427.  
  428.         AB=A+r(B-A), r in [0,1]
  429.         CD=C+s(D-C), s in [0,1]
  430.  
  431.     If AB & CD intersect, then
  432.  
  433.         A+r(B-A)=C+s(D-C), or
  434.  
  435.         XA+r(XB-XA)=XC+s(XD-XC)
  436.         YA+r(YB-YA)=YC+s(YD-YC)  for some r,s in [0,1]
  437.  
  438.     Solving the above for r and s yields
  439.  
  440.             (YA-YC)(XD-XC)-(XA-XC)(YD-YC)
  441.         r = -----------------------------  (eqn 1)
  442.             (XB-XA)(YD-YC)-(YB-YA)(XD-XC)
  443.  
  444.             (YA-YC)(XB-XA)-(XA-XC)(YB-YA)
  445.         s = -----------------------------  (eqn 2)
  446.             (XB-XA)(YD-YC)-(YB-YA)(XD-XC)
  447.  
  448.     Let I be the position vector of the intersection point, then
  449.  
  450.         I=A+r(B-A) or
  451.  
  452.         XI=XA+r(XB-XA)
  453.         YI=YA+r(YB-YA)
  454.  
  455.     By examining the values of r & s, you can also determine some
  456.     other limiting conditions:
  457.  
  458.         If 0<=r<=1 & 0<=s<=1, intersection exists
  459.             r<0 or r>1 or s<0 or s>1 line segments do not intersect
  460.  
  461.         If the denominator in eqn 1 is zero, AB & CD are parallel
  462.         If the numerator in eqn 1 is also zero, AB & CD are coincident
  463.  
  464.     If the intersection point of the 2 lines are needed (lines in this
  465.     context mean infinite lines) regardless whether the two line
  466.     segments intersect, then
  467.  
  468.         If r>1, I is located on extension of AB
  469.         If r<0, I is located on extension of BA
  470.         If s>1, I is located on extension of CD
  471.         If s<0, I is located on extension of DC
  472.  
  473.     Also note that the denominators of eqn 1 & 2 are identical.
  474.  
  475.     References:
  476.  
  477.     [O'Rourke] pp. 249-51
  478.     [Gems III] pp. 199-202 "Faster Line Segment Intersection,"
  479.  
  480.  
  481. ----------------------------------------------------------------------
  482.  
  483. Subject: 9) How do I find the intersection of a line and a plane?
  484.  
  485.     If the plane is defined as:
  486.  
  487.         a*x + b*y + c*z + d = 0
  488.  
  489.     and the line is defined as:
  490.  
  491.         x = x1 + (x2 - x1)*t = x1 + i*t
  492.         y = y1 + (y2 - y1)*t = y1 + j*t
  493.         z = z1 + (z2 - z1)*t = z1 + k*t
  494.  
  495.     Then just substitute these into the plane equation. You end up
  496.     with:
  497.  
  498.         t = - (a*x1 + b*y1 + c*z1 + d)/(a*i + b*j + c*k)
  499.  
  500.     If the denominator is zero, then the vector (a,b,c) and the vector
  501.     (i,j,k) are perpendicular.  Note that (a,b,c) is the normal to the
  502.     plane and (i,j,k) is the direction of the line.  It follows that
  503.     the line is either parallel to the plane or contained in the
  504.     plane. In either case there is no unique intersection point.
  505.  
  506.  
  507. ----------------------------------------------------------------------
  508.  
  509. Subject: 10) How do I rotate a bitmap?
  510.  
  511.     The easiest way, according to the comp.graphics faq, is to take
  512.     the rotation transformation and invert it. Then you just iterate
  513.     over the destination image, apply this inverse transformation and
  514.     find which source pixel to copy there.
  515.  
  516.     A much nicer way comes from the observation that the rotation
  517.     matrix:
  518.  
  519.         R(T) = { { cos(T), -sin(T) }, { sin(T), cos(T) } }
  520.  
  521.     is formed my multiplying three matrices, namely:
  522.  
  523.         R(T) = M1(T) * M2(T) * M3(T)
  524.  
  525.     where
  526.  
  527.         M1(T) = { { 1, -tan(T/2) },
  528.                   { 0, 1         } }
  529.         M2(T) = { { 1,      0    },
  530.                   { sin(T), 1    } }
  531.         M3(T) = { { 1, -tan(T/2) },
  532.                   { 0,         1 } }
  533.  
  534.     Each transformation can be performed in a separate pass, and
  535.     because these transformations are either row-preserving or
  536.     column-preserving, anti-aliasing is quite easy.
  537.  
  538.     Reference:
  539.  
  540.     Paeth, A. W., "A Fast Algorithm for General Raster Rotation",
  541.     Proceedings Graphics Interface '89, Canadian Information
  542.     Processing Society, 1986, 77-81
  543.     [Note - e-mail copies of this paper are no longer available]
  544.  
  545.     [Gems I]
  546.  
  547.  
  548. ----------------------------------------------------------------------
  549.  
  550. Subject: 11) How do I display a 24 bit image in 8 bits?
  551.  
  552.     [Gems I] pp. 287-293, "A Simple Method for Color Quantization:
  553.     Octree Quantization"
  554.  
  555.     B. Kurz.  Optimal Color Quantization for Color Displays.
  556.     Proceedings of the IEEE Conference on Computer Vision and Pattern
  557.     Recognition, 1983, pp. 217-224.
  558.  
  559.     [Gems II] pp. 116-125, "Efficient Inverse Color Map Computation"
  560.  
  561.         This describes an efficient technique to
  562.         map actual colors to a reduced color map,
  563.         selected by some other technique described
  564.         in the other papers.
  565.  
  566.     [Gems II] pp. 126-133, "Efficient Statistical Computations for
  567.     Optimal Color Quantization"
  568.  
  569.     Xiaolin Wu.  Color Quantization by Dynamic Programming and
  570.     Principal Analysis.  ACM Transactions on Graphics, Vol. 11, No. 4,
  571.     October 1992, pp 348-372.
  572.  
  573.  
  574. ----------------------------------------------------------------------
  575.  
  576. Subject: 12) How do I fill the area of an arbitrary shape?
  577.  
  578.  
  579.     "A Fast Algorithm for the Restoration of Images Based on Chain
  580.         Codes Description and Its Applications", L.W. Chang & K.L. Leu,
  581.         Computer Vision, Graphics, and Image Processing, vol.50,
  582.         pp296-307 (1990)
  583.  
  584.     "An Introductory Course in Computer Graphics" by Richard Kingslake,
  585.         (2nd edition) published by Chartwell-Bratt ISBN 0-86238-284-X
  586.  
  587.     [Gems I]
  588.     [Foley]
  589.     [Hearn]
  590.  
  591.  
  592. ----------------------------------------------------------------------
  593.  
  594. Subject: 13) How do I find the 'edges' in a bitmap?
  595.  
  596.     A simple method is to put the bitmap through the filter:
  597.  
  598.         -1    -1    -1
  599.         -1     8    -1
  600.         -1    -1    -1
  601.  
  602.     This will highlight changes in contrast.  Then any part of the
  603.     picture where the absolute filtered value is higher than some
  604.     threshold is an "edge".
  605.  
  606.  
  607. ----------------------------------------------------------------------
  608.  
  609. Subject: 14) How do I enlarge/sharpen/fuzz a bitmap?
  610.  
  611.  
  612. ----------------------------------------------------------------------
  613.  
  614. Subject: 15) How do I map a texture on to a shape?
  615.  
  616.     Paul S. Heckbert, "Survey of Texture Mapping", IEEE Computer
  617.     Graphics and Applications V6, #11, Nov. 1986, pp 56-67 revised
  618.     from Graphics Interface '86 version
  619.  
  620.     Eric A. Bier and Kenneth R. Sloan, Jr., "Two-Part Texture
  621.     Mappings", IEEE Computer Graphics and Applications V6 #9, Sept.
  622.     1986, pp 40-53 (projection parameterizations)
  623.  
  624.  
  625. ----------------------------------------------------------------------
  626.  
  627. Subject: 16) How do I find the area/orientation of a polygon?
  628.  
  629.     Compute the signed area.  The orientation is counter-clockwise if
  630.     this area is positive.  There's a Gem on computing signed areas.
  631.  
  632.     A slightly faster method is based on the observation that it isn't
  633.     necessary to compute the area.  One can find the lowest, rightmost
  634.     point of the polygon, and then take the cross product of the edges
  635.     fore and aft of it.  Both methods are O(n) for n vertices, but it
  636.     does seem a waste to add up the total area when a single cross
  637.     product (of just the right edges) suffices.
  638.  
  639.     The reason that the lowest, rightmost point works is that the
  640.     internal angle at this vertex is necessarily convex, strictly less
  641.     than pi (even if there are several equally-lowest points).
  642.  
  643.     The key formula is this:
  644.  
  645.         If the coordinates of vertex v_i are x_i and y_i,
  646.         twice the area of a polygon is given by
  647.  
  648.         2 A( P ) = sum_{i=0}^{n-1} (x_i y_{i+1} - y_i x_{i+1}).
  649.  
  650.     Reference:
  651.  
  652.     [O' Rourke] pp. 18-27.
  653.  
  654.  
  655. ----------------------------------------------------------------------
  656.  
  657. Subject: 17) How do I find if a point lies within a polygon?
  658.  
  659.     A quick comment - the code in the Sedgewick book Algorithms is
  660.     wrong.
  661.  
  662.     The short answer, for the FAQ, could be:
  663.  
  664.     int pnpoly(int npol, float *xp, float *yp, float x, float y)
  665.     {
  666.       int i, j, c = 0;
  667.       for (i = 0, j = npol-1; i < npol; j = i++) {
  668.         if ((((yp[i]<=y) && (y<yp[j])) ||
  669.              ((yp[j]<=y) && (y<yp[i]))) &&
  670.             (x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i]))
  671.           c = !c;
  672.       }
  673.       return c;
  674.     }
  675.  
  676.     This code is from Wm. Randolph Franklin, wrf@ecse.rpi.edu, a
  677.     professor at RPI, with some minor modifications for speed by me.
  678.     A good reference for this problem will be:
  679.  
  680.     References:
  681.  
  682.     [O'Rourke] pp. 233-238
  683.     [Gems IV]  pp. 23-45
  684.     [Glassner:RayTracing]
  685.  
  686.  
  687. ----------------------------------------------------------------------
  688.  
  689. Subject: 18) How do I find the intersection of two convex polygons?
  690.  
  691.     [O'Rourke] pp. 242-252
  692.  
  693.  
  694. ----------------------------------------------------------------------
  695.  
  696. Subject: 19) How do I detect a 'corner' in a collection of points?
  697.  
  698.     For the general solution to the problem get Ata Etemadi's software
  699.     package and associated  papers from one of the addresses below.
  700.     It's very fast and detects polygons too.
  701.  
  702.     ftp://peipa.essex.ac.uk/ipa/src/process
  703.     ftp://ftp.teleos.com/VISION-LIST-ARCHIVE/SHAREWARE
  704.  
  705.  
  706. ----------------------------------------------------------------------
  707.  
  708. Subject: 20) How do I generate a circle through three points?
  709.  
  710.     Let the three given points be a, b, c.  Use _0 and _1 to represent
  711.     x and y coordinates. The coordinates of the center p=(p_0,p_1) of
  712.     the circle determined by a, b, and c are:
  713.  
  714.             p_0 =
  715.                     ( b_1 a_0^2
  716.                     - c_1 a_0^2
  717.                     - b_1^2 a_1
  718.                     + c_1^2 a_1
  719.                     + b_0^2 c_1
  720.                     + a_1^2 b_1
  721.                     + c_0^2 a_1
  722.                     - c_1^2 b_1
  723.                     - c_0^2 b_1
  724.                     - b_0^2 a_1
  725.                     + b_1^2 c_1
  726.                     - a_1^2 c_1 )
  727.                 / D
  728.  
  729.             p_1 =
  730.                     ( a_0^2 c_0
  731.                     + a_1^2 c_0
  732.                     + b_0^2 a_0
  733.                     - b_0^2 c_0
  734.                     + b_1^2 a_0
  735.                     - b_1^2 c_0
  736.                     - a_0^2 b_0
  737.                     - a_1^2 b_0
  738.                     - c_0^2 a_0
  739.                     + c_0^2 b_0
  740.                     - c_1^2 a_0
  741.                     + c_1^2 b_0)
  742.                 / D
  743.  
  744.     where
  745.  
  746.             D = 2( a_1 c_0 + b_1 a_0 - b_1 c_0 -a_1 b_0 -c_1 a_0 + c_1 b_0 )
  747.  
  748.     The radius of the circle is then:
  749.  
  750.             r^2 = (a_0 - p_0)^2 + (a_1 - p_1)^2
  751.  
  752.     Reference:
  753.  
  754.     [O' Rourke] p. 201
  755.  
  756.  
  757. ----------------------------------------------------------------------
  758.  
  759. Subject: 21) How do I generate a bezier curve that is parallel to another bezier?
  760.  
  761.     You can't.  The only case where this is possible is when the
  762.     bezier can be represented by a straight line.  And then the
  763.     parallel 'bezier' can also be represented by a straight line.
  764.  
  765.  
  766. ----------------------------------------------------------------------
  767.  
  768. Subject: 22) How do I split a bezier at a specific value for t?
  769.  
  770.     A Bezier curve is a parametric polynomial function from the
  771.     interval [0..1] to a space, usually 2-D or 3-D.  Common Bezier
  772.     curves use cubic polynomials, so have the form
  773.  
  774.         f(t) = a3 t^3 + a2 t^2 + a1 t + a0,
  775.  
  776.     where the coefficients are points in 3-D. Blossoming converts this
  777.     polynomial to a more helpful form.  Let s = 1-t, and think of
  778.     tri-linear interpolation:
  779.  
  780.         F([s0,t0],[s1,t1],[s2,t2]) =
  781.             s0(s1(s2 c30 + t2 c21) + t1(s2 c21 + t2 c12)) +
  782.             t0(s1(s2 c21 + t2 c12) + t1(s2 c12 + t2 c03))
  783.             =
  784.             c30(s0 s1 s2) +
  785.             c21(s0 s1 t2 + s0 t1 s2 + t0 s1 s2) +
  786.             c12(s0 t1 t2 + t0 s1 t2 + t0 t1 s2) +
  787.             c03(t0 t1 t2).
  788.  
  789.     The data points c30, c21, c12, and c03 have been used in such a
  790.     way as to make the resulting function give the same value if any
  791.     two arguments, say [s0,t0] and [s2,t2], are swapped. When [1-t,t]
  792.     is used for all three arguments, the result is the cubic Bezier
  793.     curve with those data points controlling it:
  794.  
  795.           f(t) = F([1-t,t],[1-t,t],[1-t,t])
  796.                =  (1-t)^3 c30 +
  797.                  3(1-t)^2 t c21 +
  798.                  3(1-t) t^2 c12 +
  799.                  t^3 c03.
  800.  
  801.     Notice that
  802.            F([1,0],[1,0],[1,0]) = c30,
  803.            F([1,0],[1,0],[0,1]) = c21,
  804.            F([1,0],[0,1],[0,1]) = c12, _
  805.            F([0,1],[0,1],[0,1]) = c03.
  806.  
  807.     In other words, cij is obtained by giving F argument t's i of
  808.     which are 0 and j of which are 1. Since F is a linear polynomial
  809.     in each argument, we can find f(t) using a series of simple steps.
  810.     Begin with
  811.  
  812.         f000 = c30, f001 = c21, f011 = c12, f111 = c03.
  813.  
  814.     Then compute in succession:
  815.  
  816.         f00t = s f000 + t f001, f01t = s f001 + t f011,
  817.         f11t = s f011 + t f111,
  818.         f0tt = s f00t + t f01t, f1tt = s f01t + t f11t,
  819.         fttt = s f0tt + t f1tt.
  820.  
  821.     This is the de Casteljau algorithm for computing f(t) = fttt.
  822.  
  823.     It also has split the curve for the intervals [0..t] and [t..1].
  824.     The control points for the first interval are f000, f00t, f0tt,
  825.     fttt, while those for the second interval are fttt, f1tt, f11t,
  826.     f111.
  827.  
  828.     If you evaluate 3 F([1-t,t],[1-t,t],[-1,1]) you will get the
  829.     derivate of f at t. Similarly, 2*3 F([1-t,t],[-1,1],[-1,1]) gives
  830.     the second derivative of f at t, and finally using 1*2*3
  831.     F([-1,1],[-1,1],[-1,1]) gives the third derivative.
  832.  
  833.     This procedure is easily generalized to different degrees,
  834.     triangular patches, and B-spline curves.
  835.  
  836.  
  837. ----------------------------------------------------------------------
  838.  
  839. Subject: 23) How do I find a t value at a specific point on a bezier?
  840.  
  841.     In general, you'll need to find t closest to your search point.
  842.     There are a number of ways you can do this. Look at [Gems I, 607],
  843.     there's a chapter on finding the nearest point on the bezier
  844.     curve.  In my experience, digitizing the bezier curve is an
  845.     acceptable method. You can also try recursively subdividing the
  846.     curve, see if you point is in the convex hull of the control
  847.     points, and checking is the control points are close enough to a
  848.     linear line segment and find the nearest point on the line
  849.     segment, using linear interpolation and keeping track of the
  850.     subdivision level, you'll be able to find t.
  851.  
  852.  
  853. ----------------------------------------------------------------------
  854.  
  855. Subject: 24) How do I fit a bezier curve to a circle?
  856.  
  857.     Interestingly enough, bezier curves can approximate a circle but
  858.     not perfectly fit a circle.
  859.  
  860.     Michael Goldapp, "Approximation of circular arcs by cubic
  861.     polynomials" Computer Aided Geometric Design (#8 1991 pp.227-238)
  862.  
  863.     Tor Dokken and Morten Daehlen, "Good Approximations of circles by
  864.     curvature-continuous Bezier curves" Computer Aided Geometric
  865.     Design (#7 1990 pp. 33-41).
  866.  
  867.  
  868. ----------------------------------------------------------------------
  869.  
  870. Subject: 25) What is ARCBALL?
  871.  
  872.     Arcball is a general purpose 3-D rotation controller described by
  873.     Ken Shoemake in the Graphics Interface '92 Proceedings.  It
  874.     features good behavior, easy implementation, cheap execution, and
  875.     optional axis constraints. A Macintosh demo and electronic version
  876.     of the original paper (Microsoft Word format) may be obtained from
  877.     ftp::/ftp.cis.upenn.edu/pub/graphics.
  878.  
  879.  
  880. ----------------------------------------------------------------------
  881.  
  882. Subject: 26) Where can I find ARCBALL source?
  883.  
  884.     Complete source code appears in Graphics Gems IV pp. 175-192. A
  885.     fairly complete sketch of the code appeared in the original
  886.     article, in Graphics Interface 92 Proceedings, available from
  887.     Morgan Kaufmann.
  888.  
  889.  
  890. ----------------------------------------------------------------------
  891.  
  892. Subject: 27) How do I clip a polygon against a rectangle?
  893.  
  894.     This is the Sutherland-Hodgman algorithm, an old favorite that
  895.     should be covered in any textbook. Any of the references listed in
  896.     the FAQ should have it.  According to Vatti (q.v.)  "This
  897.     [algorithm] produces degenerate edges in certain concave / self
  898.     intersecting polygons that need to be removed as a special
  899.     extension to the main algorithm" (though this is not a problem if
  900.     all you are doing with the results is scan converting them.)
  901.  
  902.  
  903. ----------------------------------------------------------------------
  904.  
  905. Subject: 28) How do I clip a polygon against another polygon?
  906.  
  907.     People interested in some alpha state code, written in C++ with
  908.     templates (for example: g++) can contact Klamer Schutte,
  909.     klamer@mi.el.utwente.nl.  Or with Mosaic, at
  910.     http://ph.tn.tudelft.nl:2000/People/klamer/Klamer.html#clippoly.
  911.     Also from ftp://galaxy.ph.tn.tudelft.nl/pub/klamer/clippoly.tar.gz
  912.  
  913.  
  914. ----------------------------------------------------------------------
  915.  
  916. Subject: 29) Where can I get source for Weiler/Atherton clipping?
  917.  
  918.  
  919. ----------------------------------------------------------------------
  920.  
  921. Subject: 30) How do I generate a spline to approximate (insert curve here)?
  922.  
  923.  
  924. ----------------------------------------------------------------------
  925.  
  926. Subject: 31) Where do I get source to display (raster font format)?
  927.  
  928.  
  929. ----------------------------------------------------------------------
  930.  
  931. Subject: 32) What is morphing/how is it done?
  932.  
  933.  
  934. ----------------------------------------------------------------------
  935.  
  936. Subject: 33)How do I draw an anti-aliased line/polygon/ellipse?
  937.  
  938.  
  939. ----------------------------------------------------------------------
  940.  
  941. Subject: 34) How do I determine the intersection between a ray and a polygon
  942.  
  943.     First find the intersection between the ray and the plane in which
  944.     the polygon is situated. Then see if the point of intersection is
  945.     in the polygon.
  946.  
  947.     Reference:
  948.  
  949.     [Glassner:RayTracing]
  950.  
  951.  
  952. ----------------------------------------------------------------------
  953.  
  954. Subject: 35) How do I determine the intersection between a ray and a sphere
  955.  
  956.     Given a ray defined as:
  957.  
  958.         x = x1 + (x2 - x1)*t = x1 + i*t
  959.         y = y1 + (y2 - y1)*t = y1 + j*t
  960.         z = z1 + (z2 - z1)*t = z1 + k*t
  961.  
  962.     and a sphere defined as:
  963.  
  964.         (x - l)**2 + (y - m)**2 + (z - n)**2 = r**2
  965.  
  966.     Substituting in gives the quadratic equation:
  967.  
  968.         a*t**2 + b*t + c = 0
  969.  
  970.     where:
  971.  
  972.         a = i**2 + j**2 + k**2
  973.         b = 2*i*(x1 - l) + 2*j*(y1 - m) + 2*k*(x1 - n)
  974.         c = l**2 + m**2 + n**2 + x1**2 + y1**2 + z1**2
  975.             - 2*(l*x1 + m*y1 + n*z1) - r**2
  976.  
  977.     If the determinant of this equation is less than 0, the line does
  978.     not intersect the sphere. If it is zero, the line is tangential to
  979.     the sphere and if it is greater than zero it intersects at two
  980.     points. Solving the equation and substituting the values of t into
  981.     the ray equation will give you the points.
  982.  
  983.     Reference:
  984.  
  985.     [Glassner:RayTracing]
  986.  
  987.  
  988. ----------------------------------------------------------------------
  989.  
  990. Subject: 36) How do I determine the intersection between a ray and a bezier
  991.              surface?
  992.  
  993.     Joy I.K. and Bhetanabhotla M.N., "Ray tracing parametric surfaces
  994.     utilizing numeric techniques and ray coherence", Computer
  995.     Graphics, 16, 1986, 279-286
  996.  
  997.     Joy and Bhetanabhotla is only one approach of three major method
  998.     classes: tessellation, direct computation, and a hybrid of the
  999.     two.  Tessellation is relatively easy (you intersect the polygons
  1000.     making up the tessellation) and has no numerical problems, but can
  1001.     be inaccurate; direct is cheap on memory, but very expensive
  1002.     computationally, and can (and usually does) suffer from precision
  1003.     problems within the root solver; hybrids try to blend the two.
  1004.  
  1005.     Reference:
  1006.  
  1007.     [Glassner:RayTracing]
  1008.  
  1009.  
  1010. ----------------------------------------------------------------------
  1011.  
  1012. Subject: 37) How do I ray trace caustics?
  1013.  
  1014.     There is a discussion in [Watt:Animation], but I don't know how
  1015.     good it is.
  1016.  
  1017.     It's hard to get right.
  1018.  
  1019.     One right (but incredibly expensive) answer is:
  1020.  
  1021.     @InProceedings{mitchell-1992-illumination,
  1022.       author         = "Don P. Mitchell and Pat Hanrahan",
  1023.       title          = "Illumination From Curved Reflectors",
  1024.       year           = "1992",
  1025.       month          = "July",
  1026.       volume         = "26",
  1027.       booktitle      = "Computer Graphics (SIGGRAPH '92 Proceedings)",
  1028.       pages          = "283--291",
  1029.       keywords       = "caustics, interval arithmetic, ray tracing",
  1030.       editor         = "Edwin E. Catmull",
  1031.     }
  1032.  
  1033.     A cheat:
  1034.  
  1035.     @Article{inakage-1986-caustics,
  1036.       author         = "Masa Inakage",
  1037.       title          = "Caustics and Specular Reflection Models for
  1038.                         Spherical Objects and Lenses ",
  1039.       pages          = "379--383",
  1040.       journal        = "The Visual Computer",
  1041.       volume         = "2",
  1042.       number         = "6",
  1043.       year           = "1986",
  1044.       keywords       = "ray tracing effects",
  1045.     }
  1046.  
  1047.     very specialized:
  1048.  
  1049.     @Article{yuan-1988-gemstone,
  1050.       author         = "Ying Yuan and Tosiyasu L. Kunii and Naota
  1051.                         Inamato and Lining Sun ",
  1052.       title          = "Gemstone Fire: Adaptive Dispersive Ray Tracing
  1053.                         of Polyhedrons ",
  1054.       year           = "1988",
  1055.       month          = "November",
  1056.       journal        = "The Visual Computer",
  1057.       volume         = "4",
  1058.       number         = "5",
  1059.       pages          = "259--70",
  1060.       keywords       = "caustics",
  1061.     }
  1062.  
  1063.  
  1064. ----------------------------------------------------------------------
  1065.  
  1066. Subject: 38) How do I quickly draw a filled triangle?
  1067.  
  1068.     The easiest way is to render each line separately into an edge
  1069.     buffer. This buffer is a structure which looks like this (in C):
  1070.  
  1071.         struct { int xmin, xmax; } edgebuffer[YDIM];
  1072.  
  1073.     There is one entry for each scan line on the screen, and each
  1074.     entry is to be interpreted as a horizontal line to be drawn from
  1075.     xmin to xmax.
  1076.  
  1077.     Since most people who ask this question are trying to write fast
  1078.     games on the PC, I'll tell you where to find code.  Look at:
  1079.  
  1080.         ftp::/ftp.uwp.edu/pub/msdos/demos/programming/source
  1081.  
  1082.  
  1083. ----------------------------------------------------------------------
  1084.  
  1085. Subject: 39) Where can I get source for Voronoi/Delaunay triangulation?
  1086.  
  1087.     Source code in C for general dimension convex hull and Delaunay
  1088.     triangulation (qhull) is now available from:
  1089.  
  1090.         ftp://geom.umn.edu/pub/software/qhull.tar.Z
  1091.         ftp://geom.umn.edu/pub/software/qhull.sit.hqx for Macintosh
  1092.  
  1093.     You can view the results in 3-d and 4-d with geomview from:
  1094.  
  1095.     ftp::/geom.umn.edu:/pub/software/geomview/geomview-sgi.tar.Z  - Iris
  1096.     ftp::/geom.umn.edu:/pub/software/geomview/geomview-next.tar.Z - Next
  1097.  
  1098.     Convex hull is an easy way to build convex polytopes (just list
  1099.     the vertices).  The algorithm also produces approximate convex
  1100.     hulls.  For example, we have produced the approximate convex hull
  1101.     of 12,000 points in R^6, randomly distributed in the unit cube.
  1102.  
  1103.     The distribution includes .ps files for:
  1104.  
  1105.         Barber, C.B., Dobkin, D.P., and Huhdanpaa, H., "The Quickhull
  1106.         Algorithm for Convex Hull," Technical Report GCG53, The
  1107.         Geometry Center, Univ. of Minnesota, July 1993.
  1108.  
  1109.     References:
  1110.  
  1111.     [O' Rourke] pp. 168-204
  1112.     Three-dimensional convex hull C code in Chapter 4 (p.130-60).
  1113.  
  1114.  
  1115. ----------------------------------------------------------------------
  1116.  
  1117. Subject: 40) Where do I get source for convex hull?
  1118.  
  1119.     See the previous question on Delaunay triangulation.  The two are
  1120.     the same because the Delaunay triangulation of a set of points is
  1121.     the convex hull of the points lifted to a paraboloid.
  1122.  
  1123.     References:
  1124.     [O' Rourke] pp. 70-112
  1125.     C code for Graham's algorithm on p.80-96.
  1126.     Three-dimensional convex hull discussed in Chapter 4 (p.113-67).
  1127.     C code for the incremental algorithm on p.130-60.
  1128.  
  1129.  
  1130. ----------------------------------------------------------------------
  1131.  
  1132. Subject: 41) What is the marching cubes algorithm?
  1133.  
  1134.     The marching cubes algorithm is used in volume rendering to
  1135.     construct an isosurface from a 3D field of values.
  1136.  
  1137.     The 2D analog would be to take an image, and for each pixel, set
  1138.     it to black if the value is below some threshold, and set it to
  1139.     white if it's above the threshold.  Then smooth the jagged black
  1140.     outlines by skinning them with lines.
  1141.  
  1142.     The marching cubes algorithm tests the corner of each cube (or
  1143.     voxel) in the scalar field as being either above or below a given
  1144.     threshold.  This yields a collection of boxes with classified
  1145.     corners.  Since there are eight corners with one of two states,
  1146.     there are 256 different possible combinations for each cube.
  1147.     Then, for each cube, you replace the cube with a surface that
  1148.     meets the classification of the cube.  For example, the following
  1149.     are some 2D examples showing the cubes and their associated
  1150.     surface.
  1151.  
  1152.         - ----- +       - ----- -       - ----- +       - ----- +
  1153.         |:::'   |       |:::::::|       |::::   |       |   ':::|
  1154.         |:'     |       |:::::::|       |::::   |       |.    ':|
  1155.         |       |       |       |       |::::   |       |::.    |
  1156.         + ----- +       + ----- +       - ----- +       + ----- -
  1157.  
  1158.     The result of the marching cubes algorithm is a smooth surface
  1159.     that approximates the isosurface that is constant along a given
  1160.     threshold. This is useful for displaying a volume of oil in a
  1161.     geological volume, for example.
  1162.  
  1163.  
  1164. ----------------------------------------------------------------------
  1165.  
  1166. Subject: 42) What is the status of the patent on the "marching cubes" algorithm?
  1167.  
  1168.  
  1169. ----------------------------------------------------------------------
  1170.  
  1171. Subject: 43) How do I do a hidden surface test (backface culling) with 3d points?
  1172.  
  1173.     Just define all points of all polygons in clockwise order.
  1174.  
  1175.             c = (x3*((z1*y2)-(y1*z2))+
  1176.                 (y3*((x1*z2)-(z1*x2))+
  1177.                 (z3*((y1*x2)-(x1*y2))+
  1178.  
  1179.     x1,y1,z1, x2,y2,z2, x3,y3,z3 = the first three points of the
  1180.     polygon.
  1181.  
  1182.     If c is positive the polygon is visible. If c is negative the
  1183.     polygon is invisible (or the other way).
  1184.  
  1185.  
  1186. ----------------------------------------------------------------------
  1187.  
  1188. Subject: 44) How do I do a hidden surface test (backface culling) with 2d points?
  1189.  
  1190.     c = (x1-x2)*(y3-y2)-(y1-y2)*(x3-x2)
  1191.  
  1192.     x1,y1, x2,y2, x3,y3 = the first three points of the polygon.
  1193.  
  1194.     If c is positive the polygon is visible. If c is negative the
  1195.     polygon is invisible (or the other way).
  1196.  
  1197.  
  1198. ----------------------------------------------------------------------
  1199.  
  1200. Subject: 45) Where can I find graph layout algorithms?
  1201.  
  1202.     See the paper by Eades and Tamassia, "Algorithms for Drawing
  1203.     Graphs: An Annotated Bibliography," Tech Rep CS-89-09, Dept.  of
  1204.     CS, Brown Univ, Feb. 1989.
  1205.  
  1206.     A revised version of the annotated bibliography on graph drawing
  1207.     algorithms by Giuseppe Di Battista, Peter Eades, and Roberto
  1208.     Tamassia is now available from
  1209.  
  1210.     ftp://wilma.cs.brown.edu/pub/papers/compgeo/gdbiblio.tex.Z and
  1211.     ftp://wilma.cs.brown.edu/pub/papers/compgeo/gdbiblio.ps.Z
  1212.  
  1213.  
  1214. ----------------------------------------------------------------------
  1215.  
  1216. Subject: 46) Where can I find algorithms for 2D collision detection?
  1217.  
  1218.  
  1219. ----------------------------------------------------------------------
  1220.  
  1221. Subject: 47) Where can I find algorithms for 3D collision detection?
  1222.  
  1223.     Check out "proxima", from Purdue, which is a C++ library for 3D
  1224.     collision detection for arbitrary polyhedra.  It's a nice system;
  1225.     the algorithms are sophisticated, but the code is of modest size.
  1226.  
  1227.     There's a copy in ftp://shasta.stanford.edu/pub/nagle/proxima; it
  1228.     may not be the latest version.
  1229.  
  1230.  
  1231. ----------------------------------------------------------------------
  1232.  
  1233. Subject: 48) 3D Noise functions and turbulence in Solid texturing.
  1234.  
  1235.     See:
  1236.         ftp://gondwana.ecr.mu.oz.au/pub/siggraph92_C23.shar
  1237.         ftp://ftp.cis.ohio-state.edu/siggraph92/siggraph92_C23.shar
  1238.  
  1239.     In it there are implementations of Perlin's noise and turbulence
  1240.     functions, (By the man himself) as well as Lewis' sparse
  1241.     convolution noise function (by D. Peachey) There is also some of
  1242.     other stuff in there (Musgrave's Earth texture functions, and some
  1243.     stuff on animating gases by Ebert).
  1244.  
  1245.  
  1246. ----------------------------------------------------------------------
  1247.  
  1248. Subject: 49) How do I perform basic viewing in 3d?
  1249.  
  1250.     We describe the shape and position of objects using numbers,
  1251.     usually (x,y,z) coordinates. For example, the corners of a cube
  1252.     might be {(0,0,0), (1,0,0), (1,1,0), (0,1,0), (0,0,1), (1,0,1),
  1253.     (1,1,1), (0,1,1)}. A deep understanding of what we are saying with
  1254.     these numbers requires mathematical study, but I will try to keep
  1255.     this simple. At the least, we must understand that we have
  1256.     designated some point in space as the origin--coordinates
  1257.     (0,0,0)--and marked off lines in 3 mutually perpendicular
  1258.     directions using equally spaced units to give us (x,y,z) values.
  1259.     It might be helpful to know if we are using 1 to mean 1 foot, 1
  1260.     meter, or 1 parsec; the numbers alone do not tell us.
  1261.  
  1262.     A picture on a screen is two steps removed from the 3D world it
  1263.     depicts. First, it is a 2D projection; and second, it is a finite
  1264.     resolution approximation to the infinitely precise projection. I
  1265.     will ignore the approximation (sampling) for now. To know what the
  1266.     projection looks like, we need to know where our viewpoint is, and
  1267.     where the plane of the projection is, both in the 3D world. Think
  1268.     of it as looking out a window into a scene. As artists discovered
  1269.     some 500 years ago, each point in the world appears to be at a
  1270.     point on the window. If you move your head or look out a different
  1271.     window, everything changes. When the mathematicians understood
  1272.     what the artists were doing, they invented perspective geometry.
  1273.  
  1274.     If your viewpoint is at the origin--(0,0,0)--and the window sits
  1275.     parallel to the x-y plane but at z=1, projection is no more than
  1276.     (x,y,z) in the world appears at (x/z,y/z,1) on the plane. Distant
  1277.     points will have large z values, causing them to shrink in the
  1278.     picture. That's perspective.
  1279.  
  1280.     The trick is to take an arbitrary viewpoint and plane, and
  1281.     transform the world so we have the simple viewing situation.
  1282.     There are two steps: move the viewpoint to the origin, then move
  1283.     the viewplane to the z=1 plane. If the viewpoint is at (vx,vy,vz),
  1284.     transform every point by the translation (x,y,z) -->
  1285.     (x-vx,y-vy,z-vz). This includes the viewpoint and the viewplane.
  1286.     Now we need to rotate so that the z axis points straight at the
  1287.     viewplane, then scale so it is 1 unit away.
  1288.  
  1289.     After all this, we may find ourselves looking out upside- down. It
  1290.     is traditional to specify some direction in the world or viewplane
  1291.     as "up", and rotate so the positive y axis points that way (as
  1292.     nearly as possible if it's a world vector). Finally, we have acted
  1293.     so far as if the window was the entire plane instead of a limited
  1294.     portal. A final shift and scale transforms coordinates in the
  1295.     plane to coordinates on the screen, so that a rectangular region
  1296.     of interest (our "window") in the plane fills a rectangular region
  1297.     of the screen (our "canvas" if you like).
  1298.  
  1299.     I have left out details of how you define and perform the rotation
  1300.     of the viewplane, but I'm sure someone else will be happy to
  1301.     supply those if there is demand. It requires knowing how to
  1302.     describe a plane, and how to rotate vectors to line up. Neither is
  1303.     difficult, but this is already using a lot of net space. One
  1304.     further practical difficulty is the need to clip away parts of the
  1305.     world behind us, so -(x,y,z) doesn't pop up at (x/z,y/z,1).
  1306.     (Notice the mathematics of projection alone would allow that!) But
  1307.     all the viewing transformations can be done using translation,
  1308.     rotation, scale, and a final perspective divide. If a 4x4
  1309.     homogeneous matrix is used, it can represent everything needed,
  1310.     which saves a lot of work.
  1311.  
  1312.  
  1313. ----------------------------------------------------------------------
  1314.  
  1315. Subject: 50) How can you contribute to this FAQ?
  1316.  
  1317.     Send email to jdstone@ingr.com with your suggestions, possible
  1318.     topics, corrections, or pointers to information.  Remember, I am
  1319.     not an expert on many of these topics.  I'm the editor.
  1320.  
  1321.     Here are some possible topics that may interest many of our
  1322.     readers.
  1323.  
  1324.     Clipping...
  1325.     Splines
  1326.     Nurbs
  1327.     Image Warping/Transformation/Filtering
  1328.     Anti-aliasing
  1329.     Volume Rendering
  1330.     Morphing (synonymous with generalized Warping)
  1331.     MPEG
  1332.     JPEG
  1333.     Z-buffer/A-buffer/etc.
  1334.     interpolation (linear, spline, fft, etc.)
  1335.     Modeling tricks  (fractal mountains, trees, seashells)
  1336.  
  1337.     Surfaces
  1338.     Ray Tracing
  1339.     Reflection/Refraction
  1340.  
  1341.     1) Computing the minimum bounding boxes of various geometric
  1342.        elements such as circular arcs, parabolas, clothoids, splines,
  1343.        etc.  What is the most efficient way to do them for the
  1344.        following cases:
  1345.  
  1346.         i)  The boxes are all orthogonal to the XY plane;
  1347.         ii) The boxes is oriented such that the smallest area
  1348.             rectangular bounding boxes are computed.
  1349.  
  1350.     2) What is the most efficient way to tell if a polygon crosses
  1351.        itself?  i.e. without intersecting every edge with every edge.
  1352.  
  1353. ----------------------------------------------------------------------
  1354.  
  1355. Subject: 51) Contributors.  Who made this all possible.
  1356.  
  1357.     andrewfg@aifh.ed.ac.uk (Andrew Fitzgibbon)
  1358.     atae@spva.ph.ic.ac.uk (Ata Etemadi)
  1359.     atsao@tkk.win.net (Anson Tsao)
  1360.     barber@geom.umn.edu (Brad Barber)
  1361.     bromage@mundil.cs.mu.OZ.AU (Andrew James Bromage)
  1362.     cek@Princeton.EDU (Craig Kolb)
  1363.     fritz@riverside.MR.Net (Fritz Lott)
  1364.     hollasch@kgc.com (Steve Hollasch)
  1365.     jens_alfke@powertalk.apple.com (Jens Alfke)
  1366.     karsten@addx.stgt.sub.org (Karsten Weiss)
  1367.     lhf@visgraf.impa.br (Luiz Henrique de Figueiredo)
  1368.     orourke@cs.smith.edu (Joseph O'Rourke)
  1369.     paik@mlo.dec.com (Samuel S. Paik)
  1370.     sammy@icarus.smds.com (Samuel Murphy)
  1371.     sanguish@digifix.com (Scott Anguish)
  1372.     shoemake@graphics.cis.upenn.edu (Ken Shoemake)
  1373.     slin@esri.com (Sum Lin)
  1374.     spl@szechuan.ucsd.edu (Steve Lamont)
  1375.     weilej@rpi.edu (Jason Weiler)
  1376.  
  1377.  
  1378. $Id: algorithms,v 1.14 1994/09/29 00:54:31 jdstone Exp $
  1379.  
  1380. -- 
  1381. ----------------------------------------------------------------------
  1382. Jon Stone                             Intergraph Corporation
  1383. jdstone@ingr.com                      Boulder, CO
  1384. ----------------------------------------------------------------------
  1385.  
  1386.